﻿tTrawler.search = {
  searchTerm : "",
  checkCount : 0,
  
  startSearch : function () {
    this.searchTerm = encodeURI(document.getElementById("tTrawler_searchBox").value);
    
    tTrawler.db.clearResults();
    tTrawler.UI.search.toggleSearch();   
     
    for(i in tTrawler._services) {
      tTrawler.http.httpRequest(
        tTrawler._services[i]['url'],
        tTrawler._services[i]['method'],
        tTrawler._services[i]['query'].replace("{SearchTerm}", this.searchTerm),
        "tTrawler._services['" + i + "'].getItems(slot)");
    }; 
    this.monitorSearch();
  },
  
  monitorSearch : function () {
    this.checkCount++;
   
    if(!tTrawler.http.connectionStatus()) {
	  tTrawler.UI.search.destroyList();
	  tTrawler.UI.search.buildList(tTrawler.db.getResults());
      var t = setTimeout("tTrawler.search.monitorSearch()",1000);
    } else {      
      tTrawler.UI.search.toggleSearch();
	  this.checkCount = 0;      
      tTrawler.UI.search.destroyList();
	  
    tTrawler.UI.search.buildList(tTrawler.db.getResults());
	
    };
  }
/*--*/
}